package com.itqn.servlet;

import com.itqn.pojo.Employee;
import com.itqn.pojo.Member;
import com.itqn.service.EmployeeService;
import com.itqn.service.Impl.EmployeeServiceImpl;
import com.itqn.service.Impl.MemberServiceImpl;
import com.itqn.service.MemberService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;

@WebServlet(value = "/MemberUpdateServlet")
public class MemberUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //解决中文乱码问题
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html; charset=UTF-8");

        //获取参数
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String phone = request.getParameter("phone");
        String balance = request.getParameter("balance");
        String totalAmount = request.getParameter("totalAmount");
        //创建实体类对象
        Member member=new Member();
        member.setId(Long.parseLong(id));
        member.setName(name);
        member.setPhone(phone);
        member.setBalance(new BigDecimal(balance));
        member.setTotalAmount(new BigDecimal(totalAmount));
        //创建业务逻辑层对象
        MemberService memberService=new MemberServiceImpl();
        int result = memberService.updateMember(member);
        PrintWriter writer = response.getWriter();
        writer.write(result>0?"ok":"no");
        response.sendRedirect("/admin/member.jsp");
    }
}